home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 37 / Amiga Format CD37 (1999-02-16)(Future Publishing)(GB)(Track 1 of 3)[!][issue 1999-03].iso / -screenplay- / shareware / invasionforce / source / cyber_data.c < prev    next >
C/C++ Source or Header  |  1999-01-09  |  11KB  |  364 lines

  1. /*
  2. AI Code for Invasion Force - an Explore/Conquer Strategic Wargame
  3. Copyright (C) 1996  Brannen Hough
  4.  
  5. This program is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU General Public License
  7. as published by the Free Software Foundation; either version 2
  8. of the License, or any later version.
  9.  
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. GNU General Public License for more details.
  14.  
  15. You should have received a copy of the GNU General Public License
  16. along with this program; if not, write to the Free Software
  17. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18. */
  19.  
  20. /*
  21.     cyber_data.c -- artificial intelligence module for Empire II
  22.  
  23. */
  24.  
  25. /* This file contains all the static data used to simplify the AI
  26.     routines.  Why calculate anything when a lookup table is here?
  27. */
  28.  
  29. #include "global.h"
  30.  
  31.  
  32. /***************************
  33. ****  Global Data  *****
  34. ***************************/
  35.  
  36. int     AIDataFlag = 0;
  37.  
  38. struct  GovHist H;
  39.  
  40. struct  rtHandlerInfo *AIhandle = NULL;
  41.  
  42.  
  43. char    outbuf[256];
  44.  
  45. // This is the location where the global movement routine
  46. //        does it's computations.
  47. int        *MoveMap = NULL;
  48.  
  49. // And now, to make the Governors a list like everything else
  50. struct     MinList  GovList;
  51.  
  52.  
  53. int     NewGov = 12;
  54.  
  55. int     NewUnit = 1000;
  56.  
  57. struct  GovReqs  LastReq;    // Just make this global - easier
  58.  
  59.  
  60. struct  MinList  OpenList;
  61. struct  MinList  DoneList;      // Two lists for our new A* path finder
  62. int              *PathMap = NULL;  // And a place to record Directions
  63. int               PathMapX = 0;
  64. int               PathMapY = 0;
  65. int               Path[MAX_PATH];
  66. int               PathDiv;
  67. int               PathLength;
  68.  
  69.  
  70. /***************************
  71. ****  Data Arrays   ****
  72. ***************************/
  73.  
  74. // This data array is the most likely direction for the path searching
  75. // Has been modified - this comment needs updating
  76. // destx-orgx > 0 and desty-orgy > 0
  77. // destx-orgx > 0 and desty-orgy < 0
  78. // destx-orgx > 0 and desty-orgy = 0
  79. // destx-orgx < 0 and desty-orgy > 0
  80. // destx-orgx < 0 and desty-orgy < 0
  81. // destx-orgx < 0 and desty-orgy = 0
  82. // destx-orgx = 0 and desty-orgy > 0
  83. // destx-orgx = 0 and desty-orgy < 0
  84. const  enum  Direction   DirArray[8][6] = {
  85.     { SOUTHEAST, EAST, SOUTHWEST, NORTHEAST, WEST, NORTHWEST },
  86.     { NORTHEAST, EAST, NORTHWEST, SOUTHEAST, WEST, SOUTHWEST },
  87.     { EAST, SOUTHEAST, NORTHEAST, NORTHWEST, SOUTHWEST, WEST },
  88.     { SOUTHWEST, WEST, SOUTHEAST, NORTHWEST, EAST, NORTHEAST },
  89.     { NORTHWEST, WEST, NORTHEAST, SOUTHWEST, EAST, SOUTHEAST },
  90.     { WEST, SOUTHWEST, NORTHWEST, NORTHEAST, SOUTHEAST, EAST },
  91.     { SOUTHEAST, SOUTHWEST, WEST, EAST, NORTHWEST, NORTHEAST },
  92.     { NORTHWEST, NORTHEAST, EAST, WEST, SOUTHEAST, SOUTHWEST }
  93. };
  94.  
  95.  
  96. // And this array turns the direction into a corresponding string
  97. const  char DirString[6][10] = {
  98.         "EAST",
  99.         "SOUTHEAST",
  100.         "SOUTHWEST",
  101.         "WEST",
  102.         "NORTHWEST",
  103.         "NORTHEAST"
  104. };
  105.  
  106.  
  107. // This array returns the mode in a corresponding string
  108. const  char ModeString[9][15] = {
  109.         "NO CITY",
  110.         "EXPLORE",
  111.         "SEARCH",
  112.         "CONQUER",
  113.         "SUPPORT",
  114.         "ATTACK",
  115.         "DEFEND",
  116.         "OUTNUMBERED",
  117.         "TAKEN"
  118. };
  119.  
  120.  
  121. // This array returns the unit type in a corresponding string
  122. const  char UnitString[13][15] = {
  123.         "RIFLE",
  124.         "ARMOR",
  125.         "AIRCAV",
  126.         "BOMBER",
  127.         "FIGHTER",
  128.         "TRANSPORT",
  129.         "SUB",
  130.         "DESTROYER",
  131.         "CRUISER",
  132.         "BATTLESHIP",
  133.         "CARRIER",
  134.         "MILITIA",
  135.         "CITY"
  136. };
  137.  
  138.  
  139. // The following are the preference lists for unit types.  The
  140. //  Governors use these lists to select which unit type to 
  141. //  request.
  142. //  NOTE:  The first type in the list MUST be a type that is
  143. //  always enabled - i.e. no Bombers, Aircav, Armor, Mines.
  144. //  The selection routine defaults to the first in the list
  145. //  if a decision can't be made.  We don't want to build units
  146. //  that aren't allowed in the current game.
  147. // Multiple instances of a unit type in a single prefs list may
  148. //    be used to prevent the 'same unit type' bonus from being
  149. //    lost by small chance units at the end of a list.
  150. // I've used repeats of unit types, with 100 chances for each, at
  151. //      the ends of the prefs.  The utility of this is that any
  152. //      unit types that aren't allowed will be skipped over.  So,
  153. //      we may not reach '100' at the last unit type (if trying
  154. //      to have all the choices add up to exactly 100).  There 
  155. //      are more than one as they too might be types that are
  156. //      not allowed.
  157.  
  158. const  struct GovPrefs AI5_CITY_DEF_AIR = {
  159.   {RIFLE, FIGHTER, BOMBER, -1, -1, -1, -1, -1, -1, -1},
  160.   {0, 100, 100, 0, 0, 0, 0, 0, 0 ,0 }
  161. };
  162.  
  163. const  struct GovPrefs AI5_CITY_DEF_SEA = {
  164.   {TRANSPORT, DESTROYER, CRUISER, BATTLESHIP, DESTROYER, CRUISER, 
  165.    BATTLESHIP, -1, -1, -1},
  166.   {0, 60, 35, 5, 100, 100, 100, 0, 0, 0}
  167. };
  168.  
  169. const  struct GovPrefs AI5_CITY_SEARCH_FIRST = {
  170.   {RIFLE, FIGHTER, BOMBER, FIGHTER, BOMBER, -1, -1, -1, -1, -1},
  171.   {0, 75, 25, 100, 100, 0, 0, 0, 0, 0}
  172. };
  173.  
  174. const  struct GovPrefs AI5_CITY_SUPPORT_SEA = {
  175.   {TRANSPORT, DESTROYER, SUB, CRUISER, BATTLESHIP, CARRIER, -1, -1, -1, -1},
  176.   {15, 25, 25, 15, 10, 10, 0, 0, 0, 0}
  177. };
  178.  
  179. const  struct GovPrefs AI5_CITY_SUPPORT_LAND = {
  180.   {RIFLE, ARMOR, FIGHTER, BOMBER, AIRCAV, -1, -1, -1, -1, -1},
  181.   {20, 20, 20, 20, 20, 0, 0, 0, 0, 0}
  182. };
  183.  
  184.  
  185. const  struct GovPrefs AI5_ISLE_DEF_OWN = {
  186.   {TRANSPORT, FIGHTER, BOMBER, AIRCAV, FIGHTER, BOMBER, AIRCAV, -1, -1, -1},
  187.   {0, 60, 30, 10, 100, 100, 100, 0, 0, 0}
  188. };
  189.  
  190. const  struct GovPrefs AI5_ISLE_DEF_AIR = {
  191.   {RIFLE, FIGHTER, BOMBER, AIRCAV, FIGHTER, BOMBER, AIRCAV, -1, -1, -1},
  192.   {0, 60, 30, 10, 100, 100, 100, 0, 0, 0}
  193. };
  194.  
  195. const  struct GovPrefs AI5_ISLE_DEF_SEA = {
  196.   {TRANSPORT, DESTROYER, SUB, CRUISER, BATTLESHIP, CARRIER, DESTROYER, SUB,
  197.    CRUISER, BATTLESHIP},
  198.   {0, 40, 40, 10, 5, 5, 100, 100, 100, 100}
  199. };
  200.  
  201. const  struct GovPrefs AI5_ISLE_SEARCH_FIRST = {
  202.   {TRANSPORT, FIGHTER, BOMBER, AIRCAV, -1, -1, -1, -1, -1, -1},
  203.   {0, 100, 100, 100, 0, 0, 0, 0, 0, 0}
  204. };
  205.  
  206. const  struct GovPrefs AI5_ISLE_SEARCH_OWN = {
  207.   {TRANSPORT, AIRCAV, -1, -1, -1, -1, -1, -1, -1, -1},
  208.   {0, 100, 0, 0, 0, 0, 0, 0, 0, 0}
  209. };
  210.  
  211. const  struct GovPrefs AI5_ISLE_SEARCH_AIR = {
  212.   {RIFLE, FIGHTER, BOMBER, -1, -1, -1, -1, -1, -1, -1},
  213.   {0, 100, 100, 0, 0, 0, 0, 0, 0, 0}
  214. };
  215.  
  216. const  struct GovPrefs AI5_ISLE_SUPPORT = {
  217.   {TRANSPORT, FIGHTER, BOMBER, AIRCAV, DESTROYER, SUB, CRUISER, BATTLESHIP,
  218.    CARRIER, BOMBER},
  219.   {0, 20, 20, 10, 20, 15, 5, 5, 5, 100}
  220. };
  221.  
  222. const  struct GovPrefs AI5_TRANS_ATTACK = {
  223.   {RIFLE, ARMOR, DESTROYER, SUB, CRUISER, ARMOR, DESTROYER, SUB, CRUISER, -1},
  224.   {50, 30, 10, 5, 5, 100, 100, 100, 100, 0}
  225. };
  226.  
  227. const  struct GovPrefs AI5_TRANS_DEFEND = {
  228.   {TRANSPORT, DESTROYER, SUB, CRUISER, DESTROYER, SUB, CRUISER, -1, -1, -1},
  229.   {0, 40, 40, 20, 100, 100, 100, 0, 0, 0}
  230. };
  231.  
  232. const  struct GovPrefs AI5_CARR_ATT_SEA = {
  233.   {TRANSPORT, FIGHTER, AIRCAV, DESTROYER, SUB, CRUISER, FIGHTER, DESTROYER, 
  234.    SUB, CRUISER},
  235.   {0, 40, 10, 30, 15, 5, 100, 100, 100, 100}
  236. };
  237.  
  238. const  struct GovPrefs AI5_CARR_ATT_AIR = {
  239.   {RIFLE, FIGHTER, AIRCAV, FIGHTER, AIRCAV, -1, -1, -1, -1, -1},
  240.   {0, 75, 25, 100, 100, 0, 0, 0, 0, 0}
  241. };
  242.  
  243. const  struct GovPrefs AI5_BATT_ATTACK = {
  244.   {TRANSPORT, DESTROYER, SUB, CRUISER, DESTROYER, SUB, CRUISER, -1, -1, -1},
  245.   {0, 50, 25, 25, 100, 100, 100, 0, 0, 0}
  246. };
  247.  
  248.  
  249.  
  250. // These are old - pre version 11.  Left in as guides only.
  251. const  struct GovPrefs EXPLORE_PREFS = {
  252.         {FIGHTER, BOMBER, FIGHTER, -1, -1, -1, -1, -1, -1, -1},
  253.         {20, 30, 50, 0, 0, 0, 0, 0, 0, 0}
  254. };
  255.  
  256. const  struct GovPrefs DEFEND_LAND_PREFS = {
  257.         {RIFLE, ARMOR, FIGHTER, BOMBER, AIRCAV, -1, -1, -1, -1, -1},
  258.         {30, 30, 15, 15, 10, 0, 0, 0, 0, 0}
  259. };
  260.  
  261. const  struct GovPrefs DEFEND_PORT_PREFS = {
  262.         {RIFLE, ARMOR, FIGHTER, BOMBER, DESTROYER, SUB, CRUISER, -1, -1, -1},
  263.         {10, 15, 25, 20, 15, 10, 5, 0, 0, 0}
  264. };
  265.  
  266. const  struct GovPrefs SEARCH_PORT_PREFS = {
  267.         {RIFLE, AIRCAV, ARMOR, FIGHTER, TRANSPORT, DESTROYER, RIFLE, -1, -1, -1},
  268.         {0, 20, 10, 10, 10, 40, 10, 0, 0, 0}
  269. };
  270.  
  271. const  struct GovPrefs SEARCH_PREFS = {
  272.         {RIFLE, ARMOR, AIRCAV, BOMBER, FIGHTER, RIFLE, -1, -1, -1, -1},
  273.         {10, 20, 20, 10, 10, 30, 0, 0, 0, 0}
  274. };
  275.  
  276.  
  277. // This is a cute one - build Armor if you can, if not, build Infantry. Simple.
  278. const  struct GovPrefs CONQUER_LAND_PREFS = {
  279.         {RIFLE, ARMOR, -1, -1, -1, -1, -1, -1, -1, -1},
  280.         {0, 100, 0, 0, 0, 0, 0, 0, 0, 0}
  281. };
  282.  
  283. // FIGHTER is here so I will build something, even if AIRCAV are
  284. //    not available
  285. const  struct GovPrefs CONQUER_AIR_PREFS = {
  286.         {FIGHTER, AIRCAV, -1, -1, -1, -1, -1, -1, -1, -1},
  287.         {0, 100, 0, 0, 0, 0, 0, 0, 0, 0}
  288. };
  289.  
  290. const  struct GovPrefs CONQUER_SEA_PREFS = {
  291.         {TRANSPORT, AIRCAV, -1, -1, -1, -1, -1, -1, -1, -1},
  292.         {0, 100, -1, -1, -1, -1, -1, -1, -1, -1}
  293. };
  294.  
  295. const  struct GovPrefs CONQUER_AIR2_PREFS = {
  296.         {FIGHTER, BOMBER, -1, -1, -1, -1, -1, -1, -1, -1},
  297.         {60, 40, 0, 0, 0, 0, 0, 0, 0, 0}
  298. };
  299.  
  300. const  struct GovPrefs CONQUER_SEA2_PREFS = {
  301.         {TRANSPORT, DESTROYER, SUB, CRUISER, TRANSPORT, -1, -1, -1, -1, -1},
  302.         {0, 35, 25, 10, 30, -1, -1, -1, -1, -1}
  303. };
  304.  
  305. const  struct GovPrefs OUTNUMBERED_SEA_PREFS = {
  306.         {FIGHTER, BOMBER, SUB, -1, -1, -1, -1, -1, -1, -1},
  307.         {40, 30, 30, -1, -1, -1, -1, -1, -1, -1}
  308. };
  309.  
  310. const  struct GovPrefs OUTNUMBERED_LAND_PREFS = {
  311.         {RIFLE, ARMOR, FIGHTER, BOMBER, RIFLE, -1, -1, -1, -1, -1},
  312.         {40, 20, 10, 10, 20, -1, -1, -1, -1, -1}
  313. };
  314.  
  315. const  struct GovPrefs SUPPORT_SEA_PREFS = {
  316.         {FIGHTER, BOMBER, SUB, DESTROYER, CRUISER, TRANSPORT,
  317.             BATTLESHIP, CARRIER, -1, -1},
  318.         {10, 15, 20, 20, 10, 15, 5, 5, -1, -1}
  319. };
  320.  
  321. const  struct GovPrefs SUPPORT_LAND_PREFS = {
  322.         {RIFLE, ARMOR, FIGHTER, BOMBER, RIFLE, AIRCAV, -1, -1, -1, -1},
  323.         {0, 25, 20, 20, 25, 10, -1, -1, -1, -1}
  324. };
  325.  
  326. const  struct GovPrefs ATTACK_LAND_PREFS = {
  327.         {RIFLE, ARMOR, -1, -1, -1, -1, -1, -1, -1, -1},
  328.         {0, 100, 0, 0, 0, 0, 0, 0, 0, 0}
  329. };
  330.  
  331. // No aircav?  Build fighters
  332. const  struct GovPrefs ATTACK_AIR_PREFS = {
  333.         {FIGHTER, AIRCAV, -1, -1, -1, -1, -1, -1, -1, -1},
  334.         {0, 100, 0, 0, 0, 0, 0, 0, 0, 0}
  335. };
  336.  
  337. const  struct GovPrefs ATTACK_SEA_PREFS = {
  338.         {TRANSPORT, AIRCAV, -1, -1, -1, -1, -1, -1, -1, -1},
  339.         {0, 100, -1, -1, -1, -1, -1, -1, -1, -1}
  340. };
  341.  
  342. const  struct GovPrefs ATTACK_AIR2_PREFS = {
  343.         {FIGHTER, BOMBER, -1, -1, -1, -1, -1, -1, -1, -1},
  344.         {55, 45, 0, 0, 0, 0, 0, 0, 0, 0}
  345. };
  346.  
  347. const  struct GovPrefs ATTACK_SEA2_PREFS = {
  348.         {TRANSPORT, DESTROYER, SUB, CRUISER, TRANSPORT, -1, -1, -1, -1, -1},
  349.         {0, 30, 30, 30, 10, -1, -1, -1, -1, -1}
  350. };
  351.  
  352.  
  353. //  This next batch of data arrays helps make sure we don't change 
  354. //      production too fast - it sets a lower limit, or bounds, on
  355. //      the number of turns remaining of each type to prevent us from
  356. //      changing production during that time due to a change in the
  357. //      owning governor's mode.  Prevents us from throwing away a 
  358. //      battleship with two turns remaining on it, for example.
  359. //      Suggested by Lorne, end of Feb, 96
  360.  
  361. const   int GENERAL_MIN_TURNS[13] = {
  362.     1, 2, 3, 3, 3, 5, 5, 5, 5, 10, 10, 1, 1};
  363.  
  364.